extern char __chr[1096];

int msk7[]={0x1,0x2,0x4,0x8,0x10,0x20,0x40};
int dhrfont(str,row,col,fg,bg,scale,justify)
char *str;
int row,col,fg,bg,scale;
char justify;
{
  int target, scanline, offset, r, r2, c, d, byte, nibble, x;
  unsigned char ch;

  if (scale > 2)scale = 1;

  target = strlen(str);

  if (justify == 'm' || justify == 'M') {
      offset = (target * 7)/2;
      col = col - offset;
  }


  for(scanline=0;scanline<8;scanline++)
  {

    /* set values for vertical term */
    /* expand x scale in the vertical direction */
    r = (scanline * scale) + row; /* max 16 high */
    if (r > 191)break;
    r2 = r + 1;

    /* run the string 8 times
       if scale = 2 then print a double line
       each time which gives us a font of 16 high */
    for (byte=0;byte<target;byte++)
     {

      /* calculate the starting column for each
         run in the width of 7 pixels */
      c = (byte * 7) + col;
      if (c > 139)continue;

      d = str[byte]&0x7f;
      if (d < 32)d = 32;

      if (d == 32 && bg < 0)continue;

      offset = ((d-32) * 8) + scanline;
      ch = __chr[offset];

      if (ch == 0 && bg < 0)continue;

      for (nibble=0;nibble<7;nibble++)
       {

        x = c+nibble;
        if (x > 139)break;

        if (ch & msk7[nibble]){
		  dhrplot(x,r,fg);
		  if (scale > 1 && r2 < 192) dhrplot(x,r2,fg);
        }
        else {
		  if (bg < 0)continue;
		  dhrplot(x,r,bg);
		  if (scale > 1 && r2 < 192) dhrplot(x,r2,bg);
	    }

       }

    }
  }
  return 0;

}
